package com.pine.sunshineelder.eldertreated.web.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pine.sunshineelder.common.StringHelper;
import com.pine.sunshineelder.common.dto.JSONResponse;
import com.pine.sunshineelder.common.dto.QueryResult;
import com.pine.sunshineelder.common.entity.ElderTreatedEntity;
import com.pine.sunshineelder.eldertreated.ao.ElderTreatedAddAo;
import com.pine.sunshineelder.eldertreated.service.ElderTreatedService;
/**
 * 
 * @author 黄天静
 *
 */
@RestController
@RequestMapping("/api")
public class ElderTreatedHandler implements StringHelper {
	@Autowired
	ElderTreatedService elderTreatedService;
	@PostMapping("/eldertreated")
	public JSONResponse addUser(ElderTreatedAddAo ao) throws Exception {
		return JSONResponse.ok(elderTreatedService.addElderTreated(ao));
	}
	
	@GetMapping("/eldertreated")
	public JSONResponse listUser(String key, String  pageNo, String pageSize) throws Exception {
		Integer pageNoUse = parseInt(pageNo, null);
		Integer pageSizeUse = parseInt(pageSize, null);
		QueryResult result = elderTreatedService.queryBykeyElderTreated(key, pageNoUse, pageSizeUse);
		return JSONResponse.ok(result);
	}
	
	@GetMapping("/eldertreated/{id}")
	public JSONResponse listUser(@PathVariable String id) throws Exception {
		ElderTreatedEntity queryById = elderTreatedService.queryByIdElderTreated(id);
		return JSONResponse.ok(queryById);
	}
	
}
